(function () {
    'use strict';

    var app = angular.module('CsopApp.UiRouterStates', ['ui.router']);

//桌面
    app.config(['$stateProvider', '$urlRouterProvider',
        function ($stateProvider, $urlRouterProvider) {

            $stateProvider
                .state('Home.Main', {
                    abstract: true,
                    url: '/main',
                    templateUrl: 'views/main.html',
                    resolve: {
                        users: function (httpService) {
//                        return [
//                            { id: 0, UserName: "Alice" },
//                            { id: 1, UserName: "Bob" }
//                        ];
                            var httpOptions = {
                                method: "GET",
                                url: "jsonData/user.json",
                                encoding: "UTF-8"
                            };
                            return httpService.createService(httpOptions).then(
                                function (resp) {
                                    return resp.data.users;
                                });
                        }
                    },
                    onEnter: function () {
                        console.log("enter Desktop!!");
                    },
                    controller: function ($scope, users) {
                        console.table(users[0]);
                        $scope.users = users;
                        $scope.users[0].isActive = true;
                        $scope.Select = function ($index) {
                            $scope.users[$index].isActive = true;
                            angular.forEach($scope.users, function (user, index) {
                                if ($index !== index) {
                                    user.isActive = false;
                                }
                            })
                        }
                    }

                })
                .state('Home.Main.List', {
                    url: '',
                    templateUrl: 'partials/Desktop/desktop.list.html',
                    onEnter: function () {
                        console.log("enter main.list!!");
                    },
                    controller: function ($scope, $stateParams) {
                        console.log($stateParams);
                    }
                })
                .state('Home.Main.List2', {
                    url: '',
                    views: {
                        'list2@Home.Main': {
                            templateUrl: 'partials/Desktop/desktop.list.html'
                        }
                    },

                    onEnter: function () {
                        console.log("enter main.list2!!");
                    },
                    controller: function ($scope, $stateParams) {
                        console.log($stateParams);
                    }
                });
        }]);
})();